package com.longdaji.decoration.ui.goodscategory.content;

import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.view.ViewPager;

import com.longdaji.decoration.R;
import com.longdaji.decoration.base.BaseFragment;
import com.longdaji.decoration.ui.goodscategory.content.list.GoodsContentListFragment;
import com.longdaji.decoration.ui.goodslist.GoodsListSelectTabAdapter;

import java.util.ArrayList;
import java.util.List;

import javax.inject.Inject;

import butterknife.BindView;

/**
 * Created by longtao on 2018/1/14.
 */

public class GoodsContentFragment extends BaseFragment implements GoodsContentContract.View {
    @BindView(R.id.tlyt_goods_list_select)
    TabLayout mTlytGoodsListSelect;
    @BindView(R.id.viewpager_goods_list)
    ViewPager mViewPagerGoodsList;
    private List<BaseFragment> mFragments;
    private GoodsListSelectTabAdapter mAdapter;
    private String[] mTitles = {"全部", "最新", "最热"};
    private String mCateId;

    @Inject
    public GoodsContentFragment() {
    }

    public void setCateId(String cateId) {
        this.mCateId = cateId;
    }

    @Override
    protected int getLayoutResource() {
        return R.layout.fragment_goods_content;
    }

    @Override
    protected void initView() {
        mFragments = new ArrayList<>();
        Bundle bundleAll = new Bundle();
        bundleAll.putString("cate_id", mCateId);
        bundleAll.putString("order_by", "all");
        GoodsContentListFragment mAllFragment = GoodsContentListFragment.newInstance(bundleAll);
        Bundle bundleNew = new Bundle();
        bundleNew.putString("cate_id", mCateId);
        bundleNew.putString("order_by", "new");
        GoodsContentListFragment mNewFragment = GoodsContentListFragment.newInstance(bundleNew);
        Bundle bundleHot = new Bundle();
        bundleHot.putString("cate_id", mCateId);
        bundleHot.putString("order_by", "hot");
        GoodsContentListFragment mHotFragment = GoodsContentListFragment.newInstance(bundleHot);
        mFragments.add(mAllFragment);
        mFragments.add(mNewFragment);
        mFragments.add(mHotFragment);

        //ViewPager的适配器
        mAdapter = new GoodsListSelectTabAdapter(getChildFragmentManager(), mFragments, mTitles);
        mViewPagerGoodsList.setAdapter(mAdapter);
        mViewPagerGoodsList.setOffscreenPageLimit(3);
        //绑定
        mTlytGoodsListSelect.setupWithViewPager(mViewPagerGoodsList);
    }


}
